package com.cloud.config;

import com.cloud.properties.RedissonConfigProperties;
import com.cloud.service.RLockClient;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: ZhangKaiQiang
 * @date: 2021/4/15
 * @time: 17:23
 *
 *
 **/
@Configuration
@ConditionalOnProperty(prefix = "redisson.lock",name = "open",havingValue = "true")
@EnableConfigurationProperties(RedissonConfigProperties.class)
public class RedissonAutoConfiguration {

    private Logger logger= LoggerFactory.getLogger(RedissonAutoConfiguration.class);

    @Autowired
    private RedissonConfigProperties redissonConfigProperties;


    @Bean
    public RLockClient rLockClient(){
        RedissonConnectionManager redissonConnectionManager=new RedissonConnectionManager(redissonConfigProperties);
        RedissonClient redissonClient = redissonConnectionManager.getRedissonClient();
        return new RLockClient(redissonClient);
    }

}
